import request from '../utils/request'

// 用户认证相关API
export const authApi = {
  // 用户登录
  login: (data: { username: string; password: string }) => {
    return request.post('/auth/login', data)
  },

  // 用户注册
  register: (data: { username: string; password: string; email?: string; phone?: string }) => {
    return request.post('/auth/register', data)
  },

  // 获取用户信息
  getUserInfo: () => {
    return request.get('/auth/userinfo')
  },

  // 更新用户信息
  updateUserInfo: (data: { nickname?: string; email?: string; phone?: string; avatar?: string }) => {
    return request.put('/auth/profile', data)
  },

  // 用户登出
  logout: () => {
    return request.post('/auth/logout')
  }
}

// 课程相关API
export const courseApi = {
  // 获取课程列表
  getCourseList: () => {
    return request.get('/courses')
  },

  // 获取课程详情
  getCourseDetail: (id: number) => {
    return request.get(`/courses/${id}`)
  }
}

// 预约相关API
export const bookingApi = {
  // 获取我的预约列表
  getMyBookings: () => {
    return request.get('/bookings/my')
  },

  // 预约课程
  bookCourse: (data: { courseId: number }) => {
    return request.post('/bookings', data)
  },

  // 取消预约
  cancelBooking: (id: number) => {
    return request.delete(`/bookings/${id}`)
  }
}

// 签到相关API
export const checkinApi = {
  // 获取我的签到记录
  getMyCheckins: () => {
    return request.get('/checkins/my')
  },

  // 签到
  checkin: (data: { type?: number }) => {
    return request.post('/checkins', data)
  },

  // 签退
  checkout: () => {
    return request.post('/checkins/checkout')
  }
}

// 会员卡相关API
export const cardApi = {
  // 获取会员卡信息
  getCardInfo: () => {
    return request.get('/cards/my')
  },

  // 获取交易记录
  getTransactions: () => {
    return request.get('/cards/my/transactions')
  }
}

// 通知相关API
export const notificationApi = {
  // 获取消息通知列表
  getNotifications: () => {
    return request.get('/notifications')
  },

  // 标记通知为已读
  markAsRead: (id: number) => {
    return request.put(`/notifications/${id}/read`)
  },

  // 删除通知
  deleteNotification: (id: number) => {
    return request.delete(`/notifications/${id}`)
  }
}

// 反馈相关API
export const feedbackApi = {
  // 提交反馈
  submitFeedback: (data: { content: string; contact?: string }) => {
    return request.post('/feedback', data)
  }
}